import request from '@/utils/request'
import axios from 'axios'

/**
 * 获取顶部广告
 * @returns 
 */
export const getTopad = () => {
  return request('/home/topad', 'get')
}


// 获取网站导航下拉栏目数据

/** 生成链接对象
 * name(String): 链接名
 * href(String): 链接地址
 * ulNume(number): 属于第几个ul
 */
export const createLinkData = (name, href, ulId = -1) => {
  return {
      name,
      href,
      ulId
  }
} 

/** 生成栏目信息对象
* colID(String): 对应栏目id
* ulNum(number): 划分几个ul组
* date(Object): 链接数据  {o.name:链接名 o.href:链接地址}
*/
const createColumnList = (colId, ulNum, linkData) => {
  return {
      colId,
      ulNum,
      linkData
  }
}
export const siteNavList = [
  createColumnList('频道', 2, [createLinkData('华为专区','https://sale.vmall.com/huaweizone.html',1),
  createLinkData('教育优惠','https://www.vmall.com/portal/activity/index.html?pn=educationcenterpc',1),
  createLinkData('企业购','https://company.vmall.com/#/',2),
  createLinkData('HarmonyOS','https://sale.vmall.com/hwharmony.html',2)]),

  createColumnList('产品',2, [createLinkData('手机', 'https://www.vmall.com/list-36',1),
  createLinkData('平板','https://www.vmall.com/list-678',1),
  createLinkData('智能家居','https://www.vmall.com/list-714',1),
  createLinkData('耳机音响','https://www.vmall.com/list-652',1),
  createLinkData('生态产品','https://www.vmall.com/list-43',1),
  createLinkData('笔记本','https://www.vmall.com/list-676',2),
  createLinkData('智能穿戴','https://www.vmall.com/list-59',2),
  createLinkData('智慧屏','https://www.vmall.com/list-646',2),
  createLinkData('热销配件','https://www.vmall.com/list-54',2),
  createLinkData('增值服务','https://www.vmall.com/list-34',2)]),

  createColumnList('增值服务',2, [createLinkData('以旧换新','https://vmall.huishoubao.com/?backurl=https%3A%2F%2Fwww.vmall.com%2Flist-34',1),
  createLinkData('一口价换电池','https://www.vmall.com/order/batteryRenew',1),
  createLinkData('穿戴延保','https://www.vmall.com/member/buyServicesIndex',1),
  createLinkData('活动公告','https://www.vmall.com/notice-list/1',1),
  createLinkData('补购保障','https://www.vmall.com/member/buyServicesIndex',2),
  createLinkData('音频延保','https://www.vmall.com/member/buyServicesIndex',2),
  createLinkData('智慧屏全质保','https://www.vmall.com/member/buyServicesIndex',2)]),

  createColumnList('会员',2, [createLinkData('会员频道','https://www.vmall.com/privilege',1)])
]

// 商品搜索提示
const instance = axios.create({
  // axios 的一些配置，baseURL   timeout
  baseURL: '/huawei',
  // baseURL: 'https://openapi.vmall.com/mcp/v1/queryAssociationWordInfo',
  timeout: 5000
})
const huaweiRequest = (url, method, submitData) => {
  // 负责发请求, 请求地址, 请求方式, 提交的数据
  return instance({
    url,
    method,
    // 1. 如果是get请求     需要使用params来传递submitData  ?a=10&c=10
    // 2. 如果不是get请求    需要使用data来传递submitData    请求体传参
    // [] 设置一个动态的key, 写js表达式, js表达式的执行结果当作KEY
    // method参数: get,Get,GET  转换成小写再来判断
    [method.toLowerCase() === 'get' ? 'params' : 'data']: submitData
  })
}
export const goodsSearchTips = keyword => {
  return huaweiRequest('','post',{
    brandType: 0,
    keyword,
    country: 'CN',
    lang: 'zh-CN',
    portal: '1'
  })
}

// 获取banner
export const getBanner = () => {
  return request('/home/banner', 'get')
}

// 获取商品栏目分类
export const goodsCategoryList = [
  '手机','电脑','平板','智慧屏','穿戴','耳机音箱','门锁路由','配件','生态产品','家用电器',
  '美食酒饮','增值服务/企业商用'
]
// 获取商品栏目数据
export const getGoodsColList = (goodsName) => {
  return request('/home/goodsColumn', 'get', { goodsName })
}


// 获取小栏目导航
export const getSmallColNav = () => {
  return request('/home/smallColumn', 'get')
}


// 获取四大新品
export const getNewProducts = () => {
  return request('/home/newProducts', 'get')
}

// 获取限时秒杀
export const getLtk = () => {
  return request('/home/goodsPart/ltk', 'get')
}

// 获取限时购
export const getLtp = () => {
  return request('/home/goodsPart/ltp', 'get')
}

// 获取爆款推荐
export const getHotRecommend = () => {
  return request('/home/goodsPart/hotRecommend', 'get')
}

// 获取各商品专场
export const getGoodsPart = goodsName => {
  return request('/home/goodsPart/goods', 'get', { goodsName })
}

// 各商品更多下的链接
const moreLinks = [
  createLinkData('手机','https://www.vmall.com/list-36'),
  createLinkData('企业购专区',''),
  createLinkData('电脑','https://www.vmall.com/portal/category/?'+
  'categoryParams=%7B%22targetRoute%22%3A%22CategoryList%22%2C%22routeParams%22%3A%7B%22tagid%22%3A%5B%22TAG1151%22%5D%2C%22name%22%3A%5B%22%E5%B9%B3%E6%9D%BF%22%5D%7D%7D'),
  createLinkData('笔记本','https://www.vmall.com/list-676'),
  createLinkData('平板','https://www.vmall.com/list-678'),
  createLinkData('台式机',''),
  createLinkData('显示器',''),
]
export const getGoodsMoreLink = goodsName => {
  return moreLinks.find(item => item.name == goodsName).href
}

// // 获取底部导航数据
// const createFooterList = (name, linkData) => {
//   return {
//     name,
//     linkData
//   }
// }
// const footerLinks = [
//   createFooterList('购物指南', [createLinkData('免息分期','https://www.vmall.com/help/faq-4359.html'),
//   createLinkData('以旧换新','https://www.vmall.com/help/faq-7923.html'),
//   createLinkData('众测活动','https://www.vmall.com/help/faq-13022.html'),
//   createLinkData('企业够')])
// ]